<%@ page import="util.JdbcUtils" %>
<%@ page import="entity.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    String id = request.getParameter("id");
    User user = null;
    if (id != null){
        // 当存在 id 的时候，查询数据库中的数据
        String sql = "SELECT `name`,`username` FROM `user` WHERE `id` = ?";
        user = JdbcUtils.select(sql, User.class, id);
    } else {
        // 当不存在 id 的时候，创建一个空的 User 对象
        user = new User();
        user.setName("");
        user.setUsername("");
    }

%>

<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java实训团队协作简单案例 - 用户信息编辑页面</title>
    <link rel="shortcut icon" href="../assets/img/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../assets/vendors/font-awesome-4.7.0/css/font-awesome.min.css" />
    <link rel="stylesheet" href="../assets/css/core.css" />
    <link rel="stylesheet" href="../assets/css/index.css" />

    <link rel="stylesheet" href="../assets/css/user.css" />
</head>

<body>
<jsp:include page="/WEB-INF/tpl/header.jsp"></jsp:include>
    <section class="container">
        <jsp:include page="/WEB-INF/tpl/left.jsp"></jsp:include>
        <div class="main-right">
            <h3>新增/修改用户信息</h3>
            <form class="login-container" action="/userupdate">
                <div class="login-item">
                    <label>姓名：</label>
                    <input name="n" type="text" value="<%=user.getName()%>"/>
                </div>
                <div class="login-item">
                    <label>账号：</label>
                    <input name="u" type="text" value="<%=user.getUsername()%>"/>
                </div>
                <br>
                <%--提交表单信息的按钮--%>
                <div class="login-item">
                    <button type="submit">保存</button>
                    <input type="hidden" name="i" value="<%=id%>">
                    <button type="reset">清空</button>
                </div>
            </form>
        </div>
    </section>
</body>

</html>